/*
 * Gsoft开发框架
 * Copyright 2015-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.itcncp.ipaybox.server.resolver;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;

import com.itcncp.common.ipaybox.model.BoxRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.itcncp.ipaybox.trans.dubbo.service.DubboService;

import io.netty.channel.ChannelHandlerContext;

/**
 * 心跳解析类
 * 
 * @author LiuPeng
 * @date 2017年12月12日
 * 
 */
@Component
public class Box1002Resolver implements MsgResolverAdapter {

	private Log logger = LogFactory.getLog(getClass());

	private ExecutorService executorService = Executors.newFixedThreadPool(10);
	
	@Resource(name = "itcsApp")
	private DubboService itcsApp;
	
	/*
	 * (非 Javadoc) <p>Title: support</p> <p>Description: </p>
	 * 
	 * @param id
	 * 
	 * @see com.itcs.netty.resolver.MsgResolverAdapter#support(int)
	 */
	@Override
	public boolean support(BoxRequest boxRequest) {
		return "1002".equals(boxRequest.getMessgeType());
	}

	/*
	 * (非 Javadoc) <p>Title: resolve</p> <p>Description: </p>
	 * 
	 * @param msgResolveService
	 * 
	 * @param channelHandlerContext
	 * 
	 * @param baseMsg
	 * 
	 * @see
	 * com.itcs.netty.resolver.MsgResolverAdapter#resolve(com.itcs.netty.service.
	 * NettyMsgResolveService, io.netty.channel.ChannelHandlerContext,
	 * com.itcs.netty.common.BaseMsg)
	 */
	@Override
	public void resolve(ChannelHandlerContext channelHandlerContext, BoxRequest boxRequest) {
		logger.info("收到client[" + boxRequest.getData().getDeviceId() + "],心跳");
		
		Send2AppThread appThread = new Send2AppThread(itcsApp, channelHandlerContext, boxRequest);
		executorService.execute(appThread);
	}

}
